package com.mc.read.adminapi.service;

import com.alibaba.fastjson.JSON;
import com.mc.read.adminapi.Aspect.UserLog;
import com.mc.read.adminapi.Aspect.UserPer;
import com.mc.read.adminapi.manager.SystemManager;
import com.mc.read.common.emun.ServiceCodeEnum;
import com.mc.read.common.exception.ServiceException;
import com.mc.read.vo.request.BaseRequest;
import com.mc.read.vo.respose.BaseRespose;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liuhao
 * @date 2019/6/12 17:52
 */
@Service
@Slf4j
public class SystemService {
    @Autowired
    SystemManager systemManager;

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 查询日志列表 selectLogList
     **/
    @UserPer(permission = "system:log:select")
    public BaseRespose selectLogList(BaseRequest baseRequest) {
        log.info("查询日志列表,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = systemManager.selectLogList(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("查询日志列表 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("查询日志列表 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 查询意见反馈列表 selectOpinionList
     **/
    @UserPer(permission = "system:opinion:select")
    @UserLog(operateName = "查询意见反馈列表", type = 4)
    public BaseRespose selectOpinionList(BaseRequest baseRequest) {
        log.info("查询意见反馈列表,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = systemManager.selectOpinionList(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error(" 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error(" 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 处理意见反馈 dealOpinion
     **/
    @UserPer(permission = "system:opinion:deal")
    @UserLog(operateName = "处理意见反馈", type = 3)
    public BaseRespose dealOpinion(BaseRequest baseRequest) {
        log.info("处理意见反馈,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = systemManager.dealOpinion(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("处理意见反馈 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("处理意见反馈 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }

    /**
     * @Author:LiuHao
     * @Date:15:24 2019/5/31
     * 菜单栏渲染 selectMenuList
     **/
    public BaseRespose selectMenuList(BaseRequest baseRequest) {
        log.info("菜单栏渲染,参数为{}", JSON.toJSONString(baseRequest));
        BaseRespose baseRespose = new BaseRespose();
        try {
            baseRespose = systemManager.selectMenuList(baseRequest);
        } catch (ServiceException e) {
            e.printStackTrace();
            log.error("菜单栏渲染 异常，异常编号{}，异常代码{},参数为{}", e.getcode(), e.getMessage(), JSON.toJSONString(baseRequest));
            baseRespose.setCode(e.getcode());
            baseRespose.setDisp(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("菜单栏渲染 错误，{},参数为{}", e, JSON.toJSONString(baseRequest));
            baseRespose.setCode(ServiceCodeEnum.FAIL.getCode());
            baseRespose.setDisp(ServiceCodeEnum.FAIL.getDesc());
        }
        return baseRespose;
    }
}
